<!DOCTYPE html>
<html lang="zh">
<head>
  <meta charset="utf-8">
  <link rel="stylesheet" type="text/css" href="../js/layer/css/layui.css">
  <link rel="stylesheet" type="text/css" href="../css/admin.css">
  <meta http-equiv="pragma" content="no-cache">
  <meta http-equiv="cache-control" content="no-cache">
  <meta http-equiv="expires" content="0">
  <script>
    var searchFieldNum = 0;
  </script>
  <style>


  </style>
</head>

<body>
<div class="container-fluid-table" id="view">

  <div class="row">

    <div class="col-lg-12">
      <div class="card">
        <header class="card-header">
          <div class="card-title" style="float: left; line-height: 2.4em;">{{d.title}}</div>
          <div class="card-search">
            {{#  if(d.search == true){ }}
            <form class="search-bar1 ml-md-auto1" method="post" onsubmit="return laysearch(this);"  style="float: right;">
              <select name="field" id="search-field" class="custom-select" style="max-width: 110px!important;text-align: center;">
                {{#  arr_foreach(d.cols, function(k1, v1){ }}
                {{#  if(v1.search === true || searchFieldNum == 0){ }}
                <option value="{{v1.field}}">{{v1.title}}</option>
                {{#  } }}
                {{searchFieldNum++}}
                {{#  }); }}
              </select>
              <input id="search-val" type="text" style="width: 130px;" name="keyword" placeholder="请输入搜索内容">
              <div class="layui-btn-group">

                <button type="submit" class="layui-btn layui-btn-primary layui-btn-sm">搜索</button>

              </div>
            </form>
            {{#  } }}

          </div>
        </header>

        <div class="layui-card1">

          <div class="layui-tab layui-tab-brief" id="page-tab" lay-filter="test-hash" >
            {{#  if(d.tabs.length){ }}
            <ul class="layui-tab-title"  style="padding-left:0px;">
              {{#  arr_foreach(d.tabs, function(k1, v1){ }}
              {{#  if(k1 == 0){ }}
              <li class="layui-this" onclick="tabsLink(this)" data-where='{{v1.where}}'>{{v1.title}}</li>
              {{# }else{ }}
              <li  onclick="tabsLink(this)" data-where='{{v1.where}}'>{{v1.title}}</li>
              {{#  } }}
              {{#  }); }}
            </ul>
            {{#  } }}
          </div>
          <div class="layui-tab-content" style="padding:0px;">
            <table id="laytable" lay-filter="laytable"  style="boder:none;"></table>

            <script id="left-toolbar" type="text/html">
              <div class="layui-btn-container layui-btn-group">
                {{#  arr_foreach(d.head_toolbar, function(k1, v1){ }}
                {{#  if(v1.event != 'hidden'){ }}
                <button data-config={{=json_encode(v1)}} class="layui-btn layui-btn-primary layui-btn-sm head-event" lay-event="header"><i class="layui-icon">{{v1.ico}}</i>{{v1.title}}</button>
                {{#  } }}
                {{#  }); }}
              </div>
            </script>

          </div>

        </div>


      </div>
    </div>

  </div>

</div>

<div style="height: 20px; width: 100%;"></div>
<div style="text-align: center; background-color:#ddd; position: fixed; bottom: 0px; width: 100%;opacity: 0.8; padding-top: 8px; padding-bottom: 8px;"  id="confirmSelect">
  <button type="button" class="layui-btn" id="okSelect">确 认</button>
  <button type="button" class="layui-btn layui-bg-orange" onclick="javascript:parent.layer.closeAll();">关 闭</button>

</div>

<script type="text/javascript" src="../js/layer/layui.js"></script>
<script>
  var where = {};
  var tabWhere = [];
  window.zhanshop = null;
  ready(function() {
    layui.use(['zhanshopTable', 'zhanshop'], function() {
      zhanshop = layui.zhanshop;
      // view: function(url, elem, callback, reqMethod = 'POST', data = '', head = {}){
      zhanshop.view(API_ADDRESS + apiUrlTable +"/Sysdocument", '#view', function(
              data) {
        layui.zhanshopTable.url = API_ADDRESS + apiUrlTable +"/Sysdocument";
        layui.zhanshopTable.title = data.title;
        layui.zhanshopTable.elem = '#laytable';
        layui.zhanshopTable.toolbar = '#left-toolbar';
        layui.zhanshopTable.rowbar = data.row_toolbar; // 配置行级别菜单
        /**/
        layui.zhanshopTable.width = data.width;
        layui.zhanshopTable.height = data.height;
        layui.zhanshopTable.even = data.even;
        layui.zhanshopTable.skin = data.skin;
        layui.zhanshopTable.css = data.css;
        layui.zhanshopTable.size = data.size;
        layui.zhanshopTable.limit = data.limit;
        layui.zhanshopTable.limits = data.limits;
        layui.zhanshopTable.page = data.page;
        layui.zhanshopTable.lineStyle = data.lineStyle;
        layui.zhanshopTable.cellMinWidth = data.cellMinWidth;
        layui.zhanshopTable.data = data.data;
        /**/
        layui.zhanshopTable.idName = data.pk;
        layui.zhanshopTable.titleName = data.title_name;
        layui.zhanshopTable.pidName = data.pid_name;
        layui.zhanshopTable.schma = data.cols;
        layui.zhanshopTable.searchPage = data.searchpage;
        window.colsData = [];
        console.log(data.cols_first);
        if(zhanshop.getParam('multi') == 1){
          colsData.push({type: 'checkbox'});
        }else{
          colsData.push({type: 'radio'});
        }
        for(var i in data.cols){
          if(data.cols[i]['in_list'] !== false){
            colsData.push(layui.zhanshopTable.laycols(data.cols[i]));
          }
        }

        if(data.tabs != false){
          $("#page-tab").css("display", "");
        }
        layui.zhanshopTable.render(colsData);

        $(document).on('click', '#okSelect', function() {
          if(layui.zhanshop.getParam('multi')){
            checkSelect();
          }else{
            radioSelect();
          }
        });

        function radioSelect(){
          $("#checkData").click();
          // 单选就是替换 多选就是追加,还有已选的选择呢
          var domId = parent.layui.zhanshopFrom.currentInputId;
          var checkData = layui.table.checkStatus(layui.zhanshopTable.elem.replace('#',''));
          checkData = checkData.data;
          var documentData = {
            'file_id': checkData[0]['file_id'],
            'url': checkData[0]['url'],
            'original': checkData[0]['original'],
            'size': checkData[0]['size'],
          };
          var documentsHtml = '';
          documentsHtml += '<li class="col-6 col-md-4 col-lg-2"><figure><div class="pictext"><span class="mdi mdi-file-document icotext"></span><br>'+checkData[0]['original']+'</div><figcaption><a class="btn btn-round btn-square btn-danger inputDocumentDel" href="javascript:void(0)"><i class="mdi mdi-close document-delete"></i></a></figcaption></figure></li>';
          $('#'+domId, window.parent.document).parent().find('ul').html(documentsHtml);
          $('#'+domId, window.parent.document).val(JSON.stringify(documentData));
          parent.layer.closeAll();
        }

        function checkSelect(){
          $("#checkData").click();
          var maxLength = 12;
          // 单选就是替换 多选就是追加,还有已选的选择呢
          var domId = parent.layui.zhanshopFrom.currentInputId;
          // 已选之前已选，现在取消了
          documentsHtml = '';

          var documentDatas = [];


          var checkData = layui.table.checkStatus(layui.zhanshopTable.elem.replace('#',''));
          checkData = checkData.data;
          for(var i in checkData){
            documentDatas.push({
              'file_id': checkData[i]['file_id'],
              'url': checkData[i]['url'],
              'original': checkData[i]['original'],
              'size': checkData[i]['size'],
            });

            documentsHtml += '<li class="col-6 col-md-4 col-lg-2"><figure><div class="pictext"><span class="mdi mdi-volume-medium icotext"></span><br>'+checkData[i]['original']+'</div><figcaption><a class="btn btn-round btn-square btn-danger inputDocumentsDel" href="javascript:void(0)"><i class="mdi mdi-close documents-delete"></i></a></figcaption></figure></li>';
          }

          console.log(documentDatas);

          documentsHtml += '<li class="col-6 col-md-4 col-lg-2"><a class="add documents-add" ></a></li>';
          // 把附件处理一下
          //if(vals.length > maxLength) return layui.zhanshop.alert('最大不能选择'+maxLength+'个', danger);
          $('#'+domId, window.parent.document).parent().find('ul').html(documentsHtml);
          $('#'+domId, window.parent.document).val(JSON.stringify(documentDatas));
          parent.layer.closeAll();
        }

      }, 'POST', {"_method":"render"});
    });
  });
</script>
</body>
</html>
